function success = jcb_write_spectral_data_file(filename,lambda,sigmascat,sigmaabs,sigmaext)

formatstring = ['%20.16f'...
                '%20.16f'...
                '%20.16f'...
                '%20.16f'...
                '%20.16f'...
                '%20.16f'...
                '%20.16f\n'];
headerstring = ['%      lambda       ' ...
                '     sigmascat      ' ...
                '      sigmaabs      ' ...
                '      sigmaext      ' ...
                '   normsigmascat    ' ...
                '    normsigmaabs    ' ...
                '    normsigmaext    \n'];
unitstring   = ['%        nm         ' ...
                '        um^2        ' ...
                '        um^2        ' ...
                '        um^2        ' ...
                '         --         ' ...
                '         --         ' ...
                '         --         \n'];

if nargin<4
    error(jcb:specdata:nargin,'requires at least 4 input arguments');
end

while log10(lambda(ceil(length(lambda)*rand()))) < 2
    % i.e. a random lambda is < 100
    % lamda hasn't been scaled - multiply by 1000
    lambda=lambda*1000;
end

fid = fopen(filename,'w');
success = fid;
if fid==-1
    return
end
fprintf(fid,headerstring);
fprintf(fid,unitstring);

% mscat=max(sigmascat);
% mabs=max(sigmaabs);
% mext=max(sigmaext);
% for ii=1:length(lambda)
%     fprintf(fid,formatstring,[lambda(ii),sigmascat(ii),sigmaabs(ii),sigmaext(ii),sigmascat(ii)/mscat,sigmaabs(ii)/mabs,sigmaext(ii)/mext]);
% end
fclose(fid);